import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {ClientNoteListModel} from "../../../../model/pages/client/client-note/client-note-list/client-note-list.model";
import {Observable} from "rxjs/Observable";
import "rxjs/add/observable/of";
import * as moment from 'moment';

@Injectable()
export class ClientNoteListProvider {

    constructor(public http: HttpClient) {

    }

    convertParamsTimeToString<T>(tar,propertyArr:Array<string>):T{
        propertyArr.map((v1)=>{
            if(tar[v1]){
                tar[v1] = moment(tar[v1]*1000).format('YYYY-MM-DD HH:mm:ss');
            }
        });
        console.log(tar);
        return tar;
    }

    getClientNoteList(clientNumber: string): Observable<Array<ClientNoteListModel>> {
        return this.http.get<Array<ClientNoteListModel>>(`/note/v1/notes/${clientNumber}&undefined`);
    }

    // 查询或获取跟进列表
    getProgressList(item,notLoading=0):Observable<any>{
        //this.convertParamsTimeToString(item,['starttime','endtime']);

        return this.http.get(`/note/v1/timeLine`,{params:item})
    }

    // 删除跟进
    deleteProgress(id):Observable<any>{
        return this.http.delete('/note/v1/'+id,{responseType:'text'});
    }

}
